﻿
/* Jquery Addon olan fonksiyonlar buraya ekleniyor...*/

(function ($) {

  inputValue: function (options) {
    var settings = jQuery.extend({ allow: '', disallow: '' }, options);
    return jQuery(this).keypress
		(
			function (e) {
			  if (!e.charCode)
			    var code = String.fromCharCode(e.which);
			  else
			    var code = String.fromCharCode(e.charCode);
			  if (code && (typeof (e.keyCode) == 'undefined' || (e.keyCode != 8 && e.keyCode != 46))) {
			    if (settings.allow.length != 0 && settings.disallow.length != 0) {
			      if (settings.allow.indexOf(code) == -1) {
			        e.preventDefault();
			      } else if (settings.disallow.indexOf(code) != -1) {
			        e.preventDefault();
			      }
			    } else if (settings.allow.length != 0) {
			      if (settings.allow.indexOf(code) == -1) {
			        e.preventDefault();
			      }
			    } else if (settings.disallow.length != 0) {
			      if (settings.disallow.indexOf(code) != -1) {
			        e.preventDefault();
			      }
			    }
			  }
			  if (e.ctrlKey && code == 'v')
			    e.preventDefault();
			  $(this).bind('contextmenu', function () { return false });
			}
		);
  };

  /**
  *	input fields will accept valid email address
  */
  inputEmail: function () {
    return this.each(function () {
      jQuery(this).inputValue({ allow: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@.0123456789' });
    }
		);
  }

  /**
  *	input fields will accept digits only
  */
  inputInteger: function () {
    return this.each(function () {
      jQuery(this).inputValue({ allow: '9876543210' });
    }
		);
  };

  /**
  *	input fields will accept digits and dots.
  */
  inputFloat: function () {
    return this.each(function () {
      jQuery(this).inputValue({ allow: '0123456789.' });
    }
		);
  };

  /**
  *	input fields will accept all letters (case insensitive)
  */
  inputLetter: function () {
    return this.each(function () {
      jQuery(this).inputValue({ allow: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' });
    }
		);
  };


  checkEmail: function () {
    var result = false;
    var filter = new RegExp("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$");

    if (filter.test(jQuery(this).val()))
      result = true
    else
      result = false;

    return result;
  };

})(jQuery);



